﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BusinessObjects.BO_GetObjects;
using LibraryO2S;

public partial class controls_admin_VoteAdd : Pages_Base
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
            DataSet objDS = new DataSet("vote");
            DataTable objResult = new DataTable("result");
            DataTable objQuestion = new DataTable("question");
            objQuestion.Columns.Add("QUESTION");
            objQuestion.Columns.Add("TOTAL");
            objResult.Columns.Add("ANSWER");
            objResult.Columns.Add("NUMBER");
            objResult.Columns.Add("RATE");
            DataRow row = objQuestion.NewRow();
            row["QUESTION"] = txtQuestion.Text.Trim();
            row["TOTAL"] = "0";
            objQuestion.Rows.Add(row);
            objDS.Tables.Add(objQuestion);
            DataRow drow;
            string[] perNewAns = txtAnswer.Text.Trim().Split(new Char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string per in perNewAns)
            {
                drow = objResult.NewRow();
                drow["ANSWER"] = per;
                drow["NUMBER"] = "0";
                drow["RATE"] = "0";
                objResult.Rows.Add(drow);
            }
            objDS.Tables.Add(objResult);
            if (base.writeVote(objDS, true))
                divMessage.InnerHtml = O2S_Message.Success("Thông Báo", "Thêm mới thành công !");
            else
                divMessage.InnerHtml = O2S_Message.Warning("Lỗi", "Chưa thực hiện được vui lòng thử lại sau !");
        }
        catch (Exception ex)
        {
            divMessage.InnerHtml = O2S_Message.Error("Lỗi", "Phát hiện lỗi: " + ex.Message);
        }
    }
}
